<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <p>
      <span>姓名:</span>
      <span id="name"></span>
    </p>

    <p>
      <span>年龄:</span>
      <span id="age"></span>
    </p>
    <script>
      const spanName = document.getElementById("name");
      const spanAge = document.getElementById("age");

      const user = {};
      Object.defineProperties(user, {
        name: {
          get() {
            return spanName.innerHTML;
          },
          set(val) {
            spanName.innerHTML = val;
          },
        },
        age: {
          get() {
            return spanAge.innerHTML;
          },
          set(val) {
            spanAge.innerHTML = val;
          },
        },
      });
    </script>
  </body>
</html>
